﻿using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using UserIdentityDemo.Models;

namespace UserIdentityDemo.Data
{
    public class AlbumSeed
    {
        public static void InitData(IServiceProvider serviceProvider)
        {
            using (var context = new DataContext(serviceProvider.GetRequiredService<DbContextOptions<DataContext>>()))
            {
                if (context.Albums.Any())
                    return; // DB has been seeded
                context.Albums.AddRange(
                    new Album
                    {
                        Id = 1,
                        Artist = "Mr Zhang",
                        Publisher = CompanyNames.Islide,
                        Title = "Islide Product One"
                    },
                    new Album
                    {
                        Id = 2,
                        Artist = "Mr Li",
                        Publisher = CompanyNames.Islide,
                        Title = "Islide Product Two"
                    },
                    new Album
                    {
                        Id = 3,
                        Artist = "Mr Lu",
                        Publisher = CompanyNames.Islide,
                        Title = "Islide Product Three"
                    },
                    new Album
                    {
                        Id = 4,
                        Artist = "Mr Wang",
                        Publisher = CompanyNames.Wps,
                        Title = "Wps Product One"
                    },
                    new Album
                    {
                        Id = 5,
                        Artist = "Mr Wu",
                        Publisher = CompanyNames.Wps,
                        Title = "Wps Product Two"
                    }
                );
                context.Database.EnsureCreated();
                context.SaveChanges();
            }
        }
    }
}